﻿using HardcoreGame.Common.CustomSets;
using HardcoreGame.Content.Projectiles.Ranged;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Audio;
using Terraria.ID;
using Terraria.ModLoader;

namespace HardcoreGame.Content.Items.Weapons.Ranged.DoubleGun
{
    public class OnyxDoubleGun : BaseDoubleGun
    {
        public override int MaxBullets => 15;
        public override int ProjectileType1 => ModContent.ProjectileType<OnyxDoubleGun1>();
        public override int ProjectileType2 => ModContent.ProjectileType<OnyxDoubleGun2>();
        public override SoundStyle ReloadSound => new("HardcoreGame/Assets/Sounds/Items/I_2");
        public override void SetStaticDefaults()
        {
            CustomItemSets.DoubleGun[Type] = true;
        }
        public override void SetDefaults()
        {
            Item.DamageType = DamageClass.Ranged;
            Item.noMelee = true;
            Item.noUseGraphic = true;
            Item.useStyle = ItemUseStyleID.HiddenAnimation;
            Item.autoReuse = true;
            Item.useTime = 15;
            Item.useAnimation = 15;
            Item.shootSpeed = 10f;
            Item.knockBack = 4f;
            Item.rare = ItemRarityID.LightRed;
            Item.value = 10000;
            Item.damage = 20;
            Item.width = 40;
            Item.height = 20;
            Item.shoot = ProjectileType1;
        }

        public override void AddRecipes()
        {
            Recipe.Create(Type)
                .AddIngredient(ItemID.Handgun, 2)
                .AddIngredient(ItemID.DarkShard, 2)
                .AddIngredient(ItemID.SoulofNight, 10)
                .AddTile(TileID.MythrilAnvil)
                .Register();
        }

        protected override void Reload(Player player)
        {
            base.Reload(player);
            Vector2 direction = Vector2.Normalize(Main.MouseWorld - player.Center);

            var black = Projectile.NewProjectileDirect(
                Item.GetSource_FromThis(),
                player.position, direction,
                ProjectileType2,
                player.GetWeaponDamage(Item),
                player.GetWeaponKnockback(Item),
                player.whoAmI, 3f);

            var white = Projectile.NewProjectileDirect(
                Item.GetSource_FromThis(),
                player.position, direction,
                ProjectileType1,
                player.GetWeaponDamage(Item),
                player.GetWeaponKnockback(Item),
                player.whoAmI, 3f);

            (black.ModProjectile as OnyxDoubleGun2).animationTimer = 10;
            (white.ModProjectile as OnyxDoubleGun1).animationTimer = 10;

            player.itemTime = 40;
        }
    }
}